<template>
	<view class="animal_register">
		<view class="animal_header">
			<view class="search_header_back">
				<image @click="backGo" src="/static/back.png" mode=""></image>
			</view>
			<view class="animal_header_title">
				<view class="th2">Hello!
				</view>
				<view class="th1">Good to see you here </view>
			</view>
			<image aspectFit class="index_header_img" src="/static/login-register.png" mode=""></image>
		</view>
		<view class="animal_main">
			<view class="form">
				<view class="email">
					<text>昵称 :</text> <input v-model="nick_name" placeholder="请输入您的昵称"
						placeholder-style="font-size:14px;font-weight:100" type="text">
				</view>
				<view class="email">
					<text>账号 :</text> <input v-model="acc" placeholder="请输入您的邮箱"
						placeholder-style="font-size:14px;font-weight:100" type="number">
				</view>
				<view class="password">
					<text>密码 :</text><input v-model="passwordN" placeholder="请输入您的密码"
						placeholder-style="font-size:14px;font-weight:100" type="password">
				</view>
				<view class="password">
					<text>再次输入 :</text><input v-model="passwordO" placeholder="请再次输入您的密码"
						placeholder-style="font-size:14px;font-weight:100" type="password">
				</view>
				<view class="btn">
					<u-button text="注册" @click="registerGo"></u-button>
					<u-button text="去登录" @click="jumpGo"></u-button>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import {
		register
	} from "../../api/index.js"
	export default {
		data() {
			return {
				nick_name: "",
				acc: "",
				passwordN: "",
				passwordO: ""
			};
		},
		methods: {
			backGo() {
				uni.switchTab({
					url: "/pages/home/home"
				})
			},
			jumpGo() {
				uni.navigateTo({
					url: "/pages/login/login"
				})
			},
			registerGo() {
				if (this.nick_name != "" && this.acc != "" && this.passwordN != "" && this.passwordO != "") {
					if (this.passwordN != this.passwordO) {
						uni.showToast({
							title: "密码不一致,请重新填写",
							icon: "none"
						})
					} else {
						let password = this.passwordN

						register(this.nick_name,
							this.acc, password).then((content) => {
							let {
								data
							} = content
							console.log(data)
							if (data.code == 200) {
								uni.showToast({
									title: data.msg,
									icon: "success"
								})
							} else {
								uni.showToast({
									title: data.msg,
									icon: "error"
								})
							}
						})
					}

				} else {
					uni.showToast({
						title: "请认真填写您的信息",
						icon: "none"
					})
				}

			}
		}
	}
</script>

<style lang="scss">
	.search_header_back {
		position: absolute;
		top: 10px;
		left: 10px;
		z-index: 1;

		image {

			width: 30px;
			height: 30px;
		}
	}

	.btn {
		margin: 40px 18px 0;

		.u-button {
			background-color: #a1b275;
			color: white;
			margin-bottom: 20px;
			border-radius: 10px;
		}
	}

	.form {
		height: 300px;
		width: 100%;
		margin-top: 60px;

		.email,
		.password {
			display: flex;
			margin: 0 20px;
			padding: 20px 10px;
			margin-bottom: 10px;
			border-bottom: 2px solid #a1b275;

			input {
				margin-left: 10px;
			}
		}
	}

	.animal_register {
		height: 100vh;
		background-color: #a1b275;
	}

	.animal_header {
		width: 100%;
		height: 150px;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.index_header_img {
		display: block;
		width: 172px;
		height: 130px;
		margin-right: 20px;
		margin-top: 10px;
		transform: translateY(39px);
	}

	.animal_header_title {
		margin-top: 20px;
		margin-left: 40px;
		color: white;
		line-height: 36px;

		.th2 {
			font-size: 28px;
			font-weight: 100;
		}

		.th1 {
			font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
			font-size: 16px;
			font-weight: 100;
		}
	}

	.animal_main {
		margin-top: 20px;
		border-radius: 32px 32px 0 0;
		background-color: #f3f2f2;
		height: 497px;
		box-sizing: border-box;
		border-top: 3px solid #683931;
	}
</style>